# -*- coding:utf-8 -*-
# xpath
import requests
from lxml import etree

url = "https://dali.lianjia.com/ershoufang/"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
}


response = requests.get(url, headers=headers).text
html = etree.HTML(response)
data_list = html.xpath('//ul[@class="sellListContent"]//li[@ class="clear LOGVIEWDATA LOGCLICKDATA"]')
for data in data_list:
    item = {}
    item["title"] = data.xpath("./div[1]/div[1]/a/text()")[0]
    item["place"] = "-".join(data.xpath("./div[1]/div[2]/div[1]//a/text()"))
    item["house_info"] = data.xpath("./div[1]/div[3]/div[1]/text()")[0]
    item["total_prices"] = data.xpath("./div[1]/div[6]/div[1]//span/text()")[0] + "万"
    item["unit_price"] = data.xpath("./div[1]/div[6]/div[2]//span/text()")[0]
    print(item)


